package com.drama.api.sys.company.controller;

import com.drama.api.base.ApiIndex;
import com.drama.api.base.R;
import com.drama.api.base.RestPage;
import com.drama.api.sys.company.domain.vo.*;
import com.drama.api.sys.company.service.ISysCompanyFlowService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;


@Api( tags = ApiIndex.SysCompanyFlowController)
@RequestMapping(value = "/api/sys/flow")
@RestController
public class SysCompanyFlowController {

    @Autowired
    private ISysCompanyFlowService service;

    @ApiOperation(value = "查询流量分配集合")
    @GetMapping(value = "/list")
    public R<RestPage<List<SysCompanyFlowLogVO>>> list(
            @ApiParam(value = "查询参数") @ModelAttribute SysCompanyFlowLogSearchVO searchVO) {
        List<SysCompanyFlowLogVO> list = service.getList(searchVO);
        list=service.getFlow(list);
        RestPage restPage = new RestPage(new PageInfo(list), list);
        return new R(restPage);
    }

    @ApiOperation(value = "查询商户流量集合")
    @GetMapping(value = "/company_list")
    public R<RestPage<List<SysCompanyFlowVO>>> company_list(
            @ApiParam(value = "查询参数") @ModelAttribute SysCompanyFlowSearchVO searchVO) {
        List<SysCompanyFlowVO> list = service.getCompanyList(searchVO);
        list=service.getCompanyFlow(list);
        RestPage restPage = new RestPage(new PageInfo(list), list);
        return new R(restPage);
    }


    @ApiOperation(value = "分配/扣除流量")
    @PostMapping(value = "/op")
    public R op( @ApiParam(value = "参数") @Valid @RequestBody SysCompanyFlowLogOpVO opVO, BindingResult bindingResult) {
       service.op(opVO);
       return new R();
    }




}
